#include <stdlib.h>
#include <stdio.h>
#include <crtdbg.h>
#include "stack.h"

void inputString(const char * prompt, char * input)
{
        input[0] = 0;
        printf("%s", prompt);
        scanf("%[^\n]", input);
        fflush(stdin);
}

void main()
{
	FILE * inFile = NULL, * outFile = NULL;
	int i, s, r;
	char line[100];
	char line2[100];
	stack STACK;
	inputString("Enter input file name: ", line);
	inputString("Enter output file name: ", line2);
	inFile = fopen(line, "r");
	outFile = fopen(line2, "w");
	stack_create(&STACK);
	for(i=0; (r = fgetc(inFile))!=EOF; i++)
	{
		stack_push(&STACK, (pointer)r);
	}
	s = i;
	for(i=0; i<s; i++)
	{
		fputc((int)stack_pop(&STACK), outFile);
	}
	fclose(inFile);
	fclose(outFile);

	for (i = 0; i < 1000; i ++)
	{
		stack_push(&STACK, (pointer)i);
		_CrtCheckMemory();
	}
	stack_destroy(&STACK);

	_CrtDumpMemoryLeaks();
}